'use strict';

const basePrefix = '/api';
const articlePrefix = `${basePrefix}/article`;
const categoryPrefix = `${basePrefix}/category`;

const socketBasePrefix = '/socket';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, ws } = app;

  /**
   * http routers
   */
  router.get('/test', controller.article.test);

  // 无限加载获取文章
  router.get(`${articlePrefix}/`, controller.article.getList);
  // 根据关键词搜索文章
  router.get(`${articlePrefix}/search`, controller.article.search);
  // 获取某一 category 的文章名字列表
  router.get(`${articlePrefix}/select_by_category`, controller.article.selectNameByCategory);
  // 展示某一篇文章详细
  router.get(`${articlePrefix}/:id`, controller.article.getItem);

  // main 创建/更新文章时获取类型列表
  router.get(`${categoryPrefix}/`, controller.category.getList);

  /**
   * websocket routers
   */
  ws.route(`${socketBasePrefix}/create`, controller.create.run);
  ws.route(`${socketBasePrefix}/update`, controller.update.run);
  ws.route(`${socketBasePrefix}/refresh`, controller.refresh.run);
};
